package 面向对象初级.HomeWork;

import java.util.Scanner;

//测试类
public class Student02Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 创建可装3个学生对象的数组
        Student02[] students = new Student02[3];

        // 从键盘输入3个学生对象信息并存储到数组
        for (int i = 0; i < 3; i++) {
            System.out.print("请输入第 " + (i + 1) + " 个学生的姓名：");
            String name = scanner.nextLine();
            System.out.print("请输入第 " + (i + 1) + " 个学生的成绩：");
            double score = scanner.nextDouble();
            scanner.nextLine(); // 处理换行符

            students[i] = new Student02(name, score);
        }

        // 按照成绩排序学生对象数组
        for (int i = 0; i < students.length - 1; i++) {
            for (int j = 0; j < students.length - i - 1; j++) {
                if (students[j].getScore() > students[j + 1].getScore()) {
                    Student02 temp = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = temp;
                }
            }
        }

        // 显示排序后的学生信息
        for (Student02 student : students) {
            System.out.println(student.getInfo());
        }
        scanner.close();
    }
}
